﻿Imports System.Windows.Forms

Public Class CustomMessageBox
    Implements ContainerInterface



    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Dim oListOfUserControl As New List(Of UserControlInterface)
        Dim OKTOCLOSE As Boolean = True
        oListOfUserControl = (From u In Me.Controls.OfType(Of UserControlInterface)() Select u).ToList

        For Each Control In oListOfUserControl
            If Not Control.OkToClose() Then
                OKTOCLOSE = False
            End If
        Next

        If OKTOCLOSE Then
            Me.DialogResult = System.Windows.Forms.DialogResult.OK
            Me.Close()
        End If

    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Public Sub AddErrorToLocalErrorProvider(ByRef oControl As System.Windows.Forms.Control, ByVal strMessage As String, Optional ByVal DispatchToActivityBox As Boolean = True) Implements ContainerInterface.AddErrorToLocalErrorProvider
        LocalErrorProvider.SetError(oControl, strMessage)
    End Sub

    Public Sub RemoveErrorToLocalErrorProvider(ByRef oControl As System.Windows.Forms.Control) Implements ContainerInterface.RemoveErrorToLocalErrorProvider
        LocalErrorProvider.SetError(oControl, Nothing)
    End Sub

    Private Sub CustomMessageBox_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub CloseMessageBox()
        Me.Close()

    End Sub
End Class
